//
//  HomeGoodsCell.m
//  phmall
//
//  Created by admin on 2017/9/26.
//  Copyright © 2017年 admin. All rights reserved.
//

#import "HomeGoodsCell.h"

@implementation HomeGoodsCell
- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self){
        self.contentView.backgroundColor=[UIColor whiteColor];
        
        self.cellImage=[[UIImageView alloc]init];
        self.cellImage.image=[UIImage imageNamed:@"图片"];
        [self.contentView addSubview:self.cellImage];
        
        self.name=[[UILabel alloc]init];
        self.name.text=@"YSL玫瑰色口红(新款)";
        self.name.numberOfLines=2;
        self.name.textColor=[UIColor colorWithHexString:@"#121212"];
        self.name.font=[UIFont systemFontOfSize:13];
        [self.contentView addSubview:self.name];
        
        self.priceImg=[[UIImageView alloc]init];
        self.priceImg.image=[UIImage imageNamed:@"比索"];
        self.priceImg.contentMode=UIViewContentModeScaleAspectFill;
        [self.contentView addSubview:self.priceImg];
        
        self.price=[[UILabel alloc]init];
        self.price.font=[UIFont systemFontOfSize:15];
        self.price.text=@"6666.00";
        self.price.textColor=[UIColor orangeColor];
        [self.contentView addSubview:self.price];

        self.more=[UIButton  buttonWithType:UIButtonTypeCustom];
        [self.more setImage:[UIImage imageNamed:@"商品列表更多操作"] forState:UIControlStateNormal];
        [self.contentView addSubview:self.more];
        [self.more addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
        
        
        self.moreView=[[UIView alloc]init];
        self.moreView.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.3];
        UITapGestureRecognizer *moreViewTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(moreViewTapAction)];
        [self.moreView addGestureRecognizer:moreViewTap];
        [self.contentView addSubview:self.moreView];
        self.moreView.hidden=YES;
        
        self.collect=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.collect setImage:[UIImage imageNamed:@"未收藏商品"] forState:UIControlStateNormal];
        [self.moreView addSubview:self.collect];
        [self.collect addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.addCat=[UIButton buttonWithType:UIButtonTypeCustom];
        [self.addCat setImage:[UIImage imageNamed:@"未加入购物车"] forState:UIControlStateNormal];
        [self.moreView addSubview:self.addCat];
        [self.addCat addTarget:self action:@selector(moreAction:) forControlEvents:UIControlEventTouchUpInside];
        
        self.contentView.layer.borderWidth=0.5;
        self.contentView.layer.borderColor=[UIColor colorWithHexString:@"#efeff4"].CGColor;
    }
    
    return self;
}
-(void)layoutSubviews{
    [super layoutSubviews];
    CGSize superSize = self.contentView.frame.size;
    
    if (CGSizeEqualToSize(superSize, CGSizeZero)) {
        return;
    }
    
    [self.cellImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).with.offset(0);
        make.left.equalTo(self.contentView).with.offset(0);
        make.right.equalTo(self.contentView).with.offset(0);
        make.height.equalTo(self.cellImage.mas_width);
    }];
    
    [self.name mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.cellImage.mas_bottom).with.offset(10);
        make.left.equalTo(self.contentView).with.offset(15);
        make.right.equalTo(self.contentView).with.offset(-15);
    }];
    
    [self.price mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.with.offset(15);
        make.bottom.equalTo(self.contentView).with.offset(-10);
    }];
    
    [self.more mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.contentView).with.offset(-8);
        make.centerY.equalTo(self.price);
        make.width.height.offset(40);
    }];
    
    [self.moreView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.left.top.bottom.equalTo(self.contentView);
    }];
    
    [self.addCat mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.moreView);
        make.centerY.equalTo(self.moreView).offset(0);
        make.width.height.offset(60);
    }];
    
    [self.collect mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerX.equalTo(self.moreView);
        make.centerY.equalTo(self.moreView).offset(0);
        make.width.height.offset(60);
    }];
}
-(void)moreAction:(UIButton *)sender{
    if (self.delegate && [self.delegate respondsToSelector:@selector(moreAction:)]) {
        [self.delegate moreAction:self];
    }
    [UIView animateWithDuration:0.5 animations:^{
        self.moreView.hidden=NO;
        [self.addCat mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.moreView);
            make.centerY.equalTo(self.moreView).offset(-70);
            make.width.height.offset(60);
        }];
        
        [self.collect mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.moreView);
            make.centerY.equalTo(self.moreView).offset(70);
            make.width.height.offset(60);
        }];
        [self.addCat.superview layoutIfNeeded];
        [self.collect.superview layoutIfNeeded];
    } completion:^(BOOL finished) {
        
    }];
}
-(void)moreViewTapAction{
    [UIView animateWithDuration:0.5 animations:^{
        
        [self.addCat mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.moreView);
            make.centerY.equalTo(self.moreView).offset(0);
            make.width.height.offset(60);
        }];
        
        [self.collect mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.centerX.equalTo(self.moreView);
            make.centerY.equalTo(self.moreView).offset(0);
            make.width.height.offset(60);
        }];
        [self.addCat.superview layoutIfNeeded];
        [self.collect.superview layoutIfNeeded];
    } completion:^(BOOL finished) {
        self.moreView.hidden=YES;
    }];
}

-(void)setModel:(HomeGoodsModel *)model{
    _model=model;
    [self.cellImage sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",IMGURL,model.goods_pic]] placeholderImage:[UIImage imageNamed:@"图片空白页"]];
    self.name.text=model.goods_name;

    self.price.text=[NSString stringWithFormat:@"%@",model.goods_price];
}

@end
